<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div id="root">
    <hello @add-item="addItemHandler"></hello>

    <ul>
      <li
        v-for="item in array"
        :key="item.id"
      >
        {{item.title}}
      </li>
    </ul>
  </div>

  <script src="./libs/vue.js"></script>
  <script>
    new Vue({
      el: '#root',
      data: {
        array: [
          {id: 1, title: 'adflkjlk', isCompleted: false}
        ]
      },
      methods: {
        addItemHandler(item) {
          this.array.push({
            id: Math.random(),
            title: item,
            isCompleted: false
          })
        }
      },
      components: {
        'hello': {
          template: `
            <div>
              <input type="text" v-model="inputValue">
              <button @click="handler">添加</button>
            </div>
          `,
          data() {
            return {
              inputValue: ''
            }
          },
          methods: {
            handler() {
              console.log('in handler')
              this.$emit('add-item', this.inputValue)
              this.inputValue = ''
            }
          }
        }
      }
    })
  </script>
</body>
</html>